﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraEditors;

namespace DevExpress.CrmDemo.Win.Controls {
    public partial class MemoEditWithAutoSelect : MemoEdit {
        public MemoEditWithAutoSelect() {
        }

        private bool _focused;

        protected override void OnEnter(EventArgs e) {
            base.OnEnter(e);
            if (MouseButtons == MouseButtons.None) {
                this.SelectAll();
                _focused = true;
            }
        }

        protected override void OnLeave(EventArgs e) {
            base.OnLeave(e);
            _focused = false;
        }

        protected override void OnMouseUp(MouseEventArgs mevent) {
            base.OnMouseUp(mevent);
            if (!_focused) {
                if (SelectionLength == 0)
                    SelectAll();
                _focused = true;
            }
        }
    }
}
